package com.pig4cloud.pigx.robot.rabbitmq;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = true)
public class RabbitQueueConfiguration {

	/**
	 * 币对更新后，通知消息队列
	 *
	 * @return
	 */
	@Bean
	public FanoutExchange fanoutExchangeSymbolUpdate() {
		return new FanoutExchange(MQConstant.EXCHANGE_FANOUT_ROBOT_SYMBOL_UPDATE);
	}

	//ws 抓取价格后消息队列广播路由器
	@Bean
	public FanoutExchange fanoutExchange() {
		return new FanoutExchange(MQConstant.EXCHANGE_FANOUT_ROBOT_CALC);
	}

	//ws 计算价格完成后消息队列广播交换机
	@Bean
	public FanoutExchange fanoutIndexPriceExchange() {
		return new FanoutExchange(MQConstant.EXCHANGE_FANOUT_ROBOT_INDEX_PRICE);
	}

	@Bean
	public FanoutExchange fanoutLastPriceExchange() {
		return new FanoutExchange(MQConstant.EXCHANGE_FANOUT_ROBOT_LAST_PRICE);
	}

	@Bean
	public FanoutExchange fanoutMarkPriceExchange() {
		return new FanoutExchange(MQConstant.EXCHANGE_FANOUT_ROBOT_MARK_PRICE);
	}


	@Bean
	public Queue updateSymbolQueue() {
		return new Queue(MQConstant.QUEUE_ROBOT_SYMBOL_UPDATE);
	}

	@Bean
	public Queue calcIndexPirceQueue() {
		return QueueBuilder.durable(MQConstant.QUEUE_ROBOT_CALC_INDEX_PRICE)
				.ttl(1000)
				.build();
	}

	@Bean
	public Queue calcMarkPirceQueue() {
		return QueueBuilder.durable(MQConstant.QUEUE_ROBOT_CALC_MARK_PRICE)
				.ttl(1000)
				.build();
	}

	@Bean
	public Queue calcLastPirceQueue() {
		return QueueBuilder.durable(MQConstant.QUEUE_ROBOT_CALC_LAST_PRICE)
				.ttl(1000)
				.build();
	}

	@Bean
	public Queue updateIndexPirceQueue() {
		return new Queue(MQConstant.QUEUE_ROBOT_INDEXPRICE_UPDATE);
	}

	@Bean
	public Queue updateMarkPirceQueue() {
		return new Queue(MQConstant.QUEUE_ROBOT_MARKPRICE_UPDATE);
	}

	@Bean
	public Queue updateLastPirceQueue() {
		return new Queue(MQConstant.QUEUE_ROBOT_LASTPRICE_UPDATE);
	}

	// 交换机和队列绑定
	@Bean
	public Binding updateSymbolBinding() {
		return BindingBuilder.bind(updateSymbolQueue()).to(fanoutExchangeSymbolUpdate());
	}

	// 交换机和队列绑定
	@Bean
	public Binding calcIndexPriceBinding() {
		return BindingBuilder.bind(calcIndexPirceQueue()).to(fanoutExchange());
	}

	// 交换机和队列绑定
	@Bean
	public Binding calcMarkPriceBinding() {
		return BindingBuilder.bind(calcMarkPirceQueue()).to(fanoutExchange());
	}

	// 交换机和队列绑定
	@Bean
	public Binding calcLastPriceBinding() {
		return BindingBuilder.bind(calcLastPirceQueue()).to(fanoutExchange());
	}

	// 交换机和队列绑定
	@Bean
	public Binding updateIndexPriceBinding() {
		return BindingBuilder.bind(updateIndexPirceQueue()).to(fanoutIndexPriceExchange());
	}

	// 交换机和队列绑定
	@Bean
	public Binding updateMarkPriceBinding() {
		return BindingBuilder.bind(updateMarkPirceQueue()).to(fanoutMarkPriceExchange());
	}

	// 交换机和队列绑定
	@Bean
	public Binding updateLastPriceBinding() {
		return BindingBuilder.bind(updateLastPirceQueue()).to(fanoutLastPriceExchange());
	}
}


